
import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import moment from 'moment';
import Factory from '../factory';
import numeral from 'numeral';
import * as datetime from '../../utils/datetime'
import dataEditCreate from '../addons/DataEdit'
import dataTableCreate from '../addons/DataTable'
import * as menuService from '../../services/menus'
import COMP_QTZB_DIVI_FHQK from './Comp/COMP_QTZB_DIVI_FHQK'
import * as com from '../../utils/common';
const daoName = "MYRZDKYW";
const ButtonGroup = Button.Group;
const renderNumber = (num) => {
  let value = ''
  if (num) {
    value = numeral(num).format('0,0')
  }
  return value
};
const columns = [
  { title: '客户名称', width: 200, sorter: true, dataIndex: 'Khmc', key: 'Khmc', dispaly: true, filter: true },
  { title: '所属机构', width: 120, sorter: true, dataIndex: 'Ssjg', key: 'Ssjg', dispaly: true, filter: true },
  { title: '生效日期', width: 110, sorter: true, key: 'Ffrq', caption: "Ffrq", render: data => datetime.format(data.Ffrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '发生日期', width: 110, sorter: true, key: 'Fsrq', caption: "Fsrq", render: data => datetime.format(data.Fsrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '到期日期', width: 110, sorter: true, key: 'Dqrq', caption: "Dqrq", render: data => datetime.format(data.Dqrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '逾期日期', width: 110, sorter: true, key: 'Yqrq', caption: "Yqrq", render: data => datetime.format(data.Yqrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '下次结息日期', width: 140, sorter: true, key: 'Xcjxrq', caption: "Xcjxrq", render: data => datetime.format(data.Xcjxrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '发放金额', className: 'column-money', caption: "Ffje", render: data => com.formatNumber(data.Ffje), key: 'Ffje', width: 140, sorter: true, dispaly: true, filter: true },
  { title: '当前余额', className: 'column-money', caption: "Dqye", render: data => com.formatNumber(data.Dqye), key: 'Dqye', width: 140, sorter: true, dispaly: true, filter: true },
  { title: '逾期余额', className: 'column-money', caption: "Yqje", render: data => com.formatNumber(data.Yqje), key: 'Yqje', width: 140, sorter: true, dispaly: true, filter: true },
  { title: '自主支付金额', className: 'column-money', dataIndex: 'Zzzfje', key: 'Zzzfje', width: 140, sorter: true, dispaly: true, filter: true },
  { title: '是否逾期标志', width: 150, sorter: true, dataIndex: 'Sfyqbz', key: 'Sfyqbz', dispaly: true, filter: true },
  { title: '十二级分类评级代码', width: 180, sorter: true, dataIndex: 'Sejfl', key: 'Sejfl', dispaly: true, filter: true },
  { title: '当前余额方向代码', width: 170, sorter: true, dataIndex: 'Dqyefxdm', key: 'Dqyefxdm', dispaly: true, filter: true },
  { title: '逾期余额方向代码', width: 170, sorter: true, dataIndex: 'Yqyefxdm', key: 'Yqyefxdm', dispaly: true, filter: true },
  { title: '利息调整借贷方向代码', width: 200, sorter: true, dataIndex: 'lxtzjd', key: 'lxtzjd', dispaly: true, filter: true },
  { title: '新企业规模代码', width: 170, sorter: true, dataIndex: 'Xqydmddm', key: 'Xqydmddm', dispaly: true, filter: true },
  { title: '货币代码', width: 120, sorter: true, dataIndex: 'Hbdm', key: 'Hbdm', dispaly: true, filter: true },
  { title: '货币', width: 100, sorter: true, dataIndex: 'Huobi', key: 'Huobi', dispaly: true, filter: true },
  { title: '科目号', width: 120, sorter: true, dataIndex: 'Kmh', key: 'Kmh', dispaly: true, filter: true },
  { title: '利率属性代码', width: 150, sorter: true, dataIndex: 'Llsxdm', key: 'Llsxdm', dispaly: true, filter: true },
  { title: '执行利率', width: 150, sorter: true, caption: "Zxll", render: data => com.TosWxS(data.Zxll), key: 'Zxll', dispaly: true, filter: true },
  // { title: '客户经理1', width: 100, sorter: false, dataIndex: 'YG1', key: 'YG1', dispaly: true, filter: false },
  // { title: '分配比例1(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB1', render: data => renderNumber(data.ZB1), key: 'ZB1', dispaly: true, filter: false },
  // { title: '客户经理2', width: 100, sorter: false, dataIndex: 'YG2', key: 'YG2', dispaly: true, filter: false },
  // { title: '分配比例2(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB2', render: data => renderNumber(data.ZB2), key: 'ZB2', dispaly: true, filter: false },
  // { title: '客户经理3', width: 100, sorter: false, dataIndex: 'YG3', key: 'YG3', dispaly: true, filter: false },
  // { title: '分配比例3(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB3', render: data => renderNumber(data.ZB3), key: 'ZB3', dispaly: true, filter: false },
  // { title: '客户经理4', width: 100, sorter: false, dataIndex: 'YG4', key: 'YG4', dispaly: true, filter: false },
  // { title: '分配比例4(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB4', render: data => renderNumber(data.ZB4), key: 'ZB4', dispaly: true, filter: false },
  // { title: '客户经理5', width: 100, sorter: false, dataIndex: 'YG5', key: 'YG5', dispaly: true, filter: false },
  // { title: '分配比例5(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB5', render: data => renderNumber(data.ZB5), key: 'ZB5', dispaly: true, filter: false },
];
const controls = [
  { name: 'Sfyqbz', required: true, type: 'text', label: '是否逾期标志', grid: 12 / 24 },
  { name: 'Sejfl', required: true, type: 'text', label: '十二级分类评级结果代码', grid: 12 / 24 },
  { name: 'Dqyefxdm', required: true, type: 'text', label: '当前余额方向代码', grid: 12 / 24 },
  { name: 'Yqyefxdm', required: true, type: 'text', label: '逾期余额方向代码', grid: 12 / 24 },
  { name: 'lxtzjd', required: true, type: 'text', label: '利息调整借贷方向代码', grid: 12 / 24 },
  { name: 'Khmc', required: true, type: 'text', label: '客户名称', grid: 12 / 24 },
  { name: 'Xqydmddm', required: true, type: 'text', label: '新企业规模代码', grid: 12 / 24 },
  { name: 'Hbdm', required: true, type: 'text', label: '货币代码', grid: 12 / 24 },
  { name: 'Huobi', required: true, type: 'text', label: '货币', grid: 12 / 24 },
  { name: 'Kmh', required: true, type: 'text', label: '科目号', grid: 12 / 24 },
  { name: 'Ssjg', required: true, type: 'text', label: '所属机构', grid: 12 / 24 },
  { name: 'Llsxdm', required: true, type: 'text', label: '利率属性代码', grid: 12 / 24 },
  { name: 'Zxll', required: true, type: 'text', label: '执行利率', grid: 12 / 24 },
  { name: 'Ffrq', required: true, type: 'date', label: '发放日期', grid: 12 / 24, dataType: "date" },
  { name: 'Fsrq', required: true, type: 'date', label: '发生日期', grid: 12 / 24 },
  { name: 'Dqrq', required: true, type: 'date', label: '到期日期', grid: 12 / 24 },
  { name: 'Yqrq', required: true, type: 'date', label: '逾期日期', grid: 12 / 24 },
  { name: 'Xcjxrq', required: true, type: 'date', label: '下次结息日期',grid: 12 / 24 },
  { name: 'Ffje', required: true, type: 'number', label: '发放金额', grid: 12 / 24 },
  { name: 'Dqye', required: true, type: 'number', label: '当前余额', grid: 12 / 24 },
  { name: 'Yqje', required: true, type: 'number', label: '逾期余额', grid: 12 / 24 },
  { name: 'Zzzfje', required: true, type: 'number', label: '自主支付金额', grid: 12 / 24 },
]
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
class MYRZDKYWS extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataChange: false
    };
  }
  componentDidMount() {
    this.props.dispatch({
      type: `${daoName}/setKeyName`,
      payload: { keyName: "ID", permID: this.props.permID }
    });
    this.props.dispatch({
      type: `${daoName}/fetch`,
      payload: { daoName, page: 1, pageSize: 20 }
    });
    this.loadOptionData();
  }
  loadOptionData() {
    let options = []
    controls.map(c => {
      if (c.fetch) {
        let f = c.fetch;
        if (c.type === 'cascader-select') {
          f.isCascader = true;
        }
        if (c.type !== 'search') {
          options.push(f);
        }
      }
    })
    if (daoName && options.length > 0) {
      this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
    }
  }
  showModelHandler(isAdd) {
    let key = null
    if (!isAdd) {
      const len = this.props.selectedRowKeys.length;
      if (len === 0) {
        message.info('请选择要编辑的行，如果选择了多行，则使用最后一次选择！');
        return;
      }
      key = this.props.selectedRowKeys[len - 1]
    }
    this.props.dispatch({
      type: `${daoName}/openEdit`,
      payload: { key }
    });
  }
  hideEditHandler() {
    if (this.state.dataChange) {
      this.props.dispatch({
        type: `${daoName}/reload`,
        payload: { daoName },
      });
      this.state.dataChange = false;
    }
    this.props.dispatch({
      type: `${daoName}/hideEdit`
    });
  };
  render() {
    let { showEdit, record, permID, popedomTypes } = this.props
    // const pTypes = popedomTypes[permID]
    // let data = []
    // if (pTypes.indexOf('6') !== -1) {
    //   let button = { value: '2', label: '业绩认定', onClick: this.showModelHandler.bind(this, false) }
    //   data.push(button)
    // }
    // const controlsFilter = [
    //   { name: 'CX', required: false, type: 'button-group', data: data, grid: 5 / 24 },
    // ];
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div>
          {/* <div className={styles.create}>
            <EditFrom ref="findForm" daoName={daoName} controls={controlsFilter} clearItemMargin={true} selectFirst={false} />
          </div> */}
          <COMP_QTZB_DIVI_FHQK ref="divi" jlid={record.JLID} ywid={12} title={"业绩分配"} showEdit={showEdit} parentModel={daoName} />
          <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID} />
        </div>
      </div>
    )
  }
}
function mapStateToProps(state) {
  const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
  const { userID, orgID, pOrgID, popedomTypes } = state.menus;
  return {
    userID,
    orgID,
    pOrgID,
    popedomTypes,
    showEdit,
    selectedRowKeys,
    keyName,
    record
  }
}
MYRZDKYWS = connect(mapStateToProps)(MYRZDKYWS)
export default MYRZDKYWS;
let render = (props) => React.createElement(MYRZDKYWS, props);

let f = new Factory()
f.set("MYRZDKYWS", render)
